/**
 * 用户管理相关类型定义
 */

// 用户基本信息
export interface User {
  id: string
  userName: string
  email: string
  name?: string
  surname?: string
  phoneNumber?: string
  isActive: boolean
  lockoutEnabled: boolean
  lockoutEnd?: string
  twoFactorEnabled: boolean
  accessFailedCount: number
  concurrencyStamp: string
  securityStamp: string
  creationTime: string
  lastModificationTime?: string
  creatorId?: string
  lastModifierId?: string
  lastLoginTime?: string
  tenantId?: string
  tenantName?: string
  roles?: string[]
  claims?: UserClaim[]
  externalLogins?: UserExternalLogin[]
  organizationUnits?: string[]
}

// 用户创建请求
export interface CreateUserRequest {
  userName: string
  email: string
  name?: string
  surname?: string
  phoneNumber?: string
  password: string
  roleNames?: string[]
  organizationUnitIds?: string[]
  isActive?: boolean
  lockoutEnabled?: boolean
  sendConfirmationEmail?: boolean
  sendPasswordResetEmail?: boolean
  tenantId?: string
}

// 用户更新请求
export interface UpdateUserRequest {
  userName: string
  email: string
  name?: string
  surname?: string
  phoneNumber?: string
  isActive: boolean
  lockoutEnabled: boolean
  twoFactorEnabled: boolean
  roleNames?: string[]
  organizationUnitIds?: string[]
  concurrencyStamp: string
}

// 用户查询参数
export interface UserQueryParams {
  filter?: string
  isActive?: boolean
  role?: string
  organizationUnitId?: string
  tenantId?: string
  sorting?: string
  skipCount?: number
  maxResultCount?: number
  includeRoleNames?: boolean
  includeOrganizationUnits?: boolean
}

// 用户查询结果
export interface UserQueryResult {
  items: User[]
  totalCount: number
}

// 用户统计信息
export interface UserStatistics {
  totalUsers: number
  activeUsers: number
  inactiveUsers: number
  lockedUsers: number
  twoFactorEnabledUsers: number
  recentRegistrations: number
  recentLogins: number
  usersByTenant: Array<{
    tenantId: string
    tenantName: string
    userCount: number
  }>
  usersByRole: Array<{
    roleName: string
    userCount: number
  }>
}

// 用户登录历史
export interface UserLoginHistory {
  id: string
  userId: string
  userName: string
  tenantId?: string
  tenantName?: string
  loginTime: string
  logoutTime?: string
  ipAddress: string
  userAgent: string
  loginProvider?: string
  isSuccess: boolean
  errorMessage?: string
  browserInfo?: string
  platform?: string
  device?: string
  location?: {
    country?: string
    region?: string
    city?: string
    latitude?: number
    longitude?: number
  }
}

// 用户声明
export interface UserClaim {
  id: string
  userId: string
  claimType: string
  claimValue: string
  tenantId?: string
  creationTime: string
}

// 用户外部登录
export interface UserExternalLogin {
  id: string
  userId: string
  loginProvider: string
  providerKey: string
  providerDisplayName?: string
  tenantId?: string
  creationTime: string
}

// 用户安全日志
export interface UserSecurityLog {
  id: string
  userId: string
  userName: string
  tenantId?: string
  tenantName?: string
  action: string
  actionTime: string
  ipAddress: string
  userAgent: string
  clientId?: string
  correlationId?: string
  details?: string
  properties?: Record<string, any>
}

// 用户权限
export interface UserPermission {
  name: string
  displayName?: string
  description?: string
  isGranted: boolean
  providerName?: string
  providerKey?: string
}

// 用户角色分配
export interface UserRoleAssignment {
  userId: string
  roleId: string
  roleName: string
  isAssigned: boolean
  assignmentTime?: string
}

// 用户组织单元分配
export interface UserOrganizationUnitAssignment {
  userId: string
  organizationUnitId: string
  organizationUnitName: string
  isAssigned: boolean
  assignmentTime?: string
}

// 用户在线状态
export interface UserOnlineStatus {
  userId: string
  userName: string
  displayName?: string
  isOnline: boolean
  lastActivityTime: string
  connectionId?: string
  ipAddress?: string
  userAgent?: string
}

// 用户活动日志
export interface UserActivityLog {
  id: string
  userId: string
  userName: string
  tenantId?: string
  tenantName?: string
  activity: string
  activityTime: string
  category: string
  level: 'Information' | 'Warning' | 'Error'
  details?: string
  ipAddress?: string
  userAgent?: string
  properties?: Record<string, any>
}

// 用户导入请求
export interface ImportUserRequest {
  file: File
  tenantId?: string
  sendWelcomeEmail: boolean
  sendPasswordResetEmail: boolean
  defaultPassword?: string
  overwriteExisting: boolean
}

// 用户导出请求
export interface ExportUserRequest {
  tenantId?: string
  roleNames?: string[]
  organizationUnitIds?: string[]
  isActive?: boolean
  format: 'Json' | 'Excel' | 'Csv'
  includeSensitiveData: boolean
}

// 用户批量操作请求
export interface BulkUserOperationRequest {
  userIds: string[]
  operation: 'Activate' | 'Deactivate' | 'Delete' | 'Lock' | 'Unlock' | 'AssignRole' | 'RemoveRole' | 'AssignOrganizationUnit' | 'RemoveOrganizationUnit'
  parameters?: Record<string, any>
}

// 用户密码管理
export interface UserPasswordManagement {
  userId: string
  currentPassword?: string
  newPassword: string
  confirmPassword: string
  forcePasswordChangeNextLogin?: boolean
  sendPasswordResetEmail?: boolean
}

// 用户双因素认证设置
export interface UserTwoFactorSettings {
  userId: string
  isEnabled: boolean
  providers: TwoFactorProvider[]
  recoveryCodes?: string[]
  defaultProvider?: string
}

// 双因子认证提供商
export interface TwoFactorProvider {
  name: string
  displayName: string
  isAvailable: boolean
  isConfigured: boolean
  isEnabled: boolean
  lastConfiguredTime?: string
}

// 用户会话信息
export interface UserSession {
  id: string
  userId: string
  userName: string
  tenantId?: string
  tenantName?: string
  sessionId: string
  loginTime: string
  lastActivityTime: string
  ipAddress: string
  userAgent: string
  isActive: boolean
  logoutTime?: string
  deviceInfo?: {
    platform: string
    browser: string
    version: string
    mobile: boolean
  }
  location?: {
    country?: string
    region?: string
    city?: string
  }
}

// 用户通知设置
export interface UserNotificationSettings {
  userId: string
  receiveEmailNotifications: boolean
  receiveSystemNotifications: boolean
  receiveSecurityNotifications: boolean
  receiveTenantNotifications: boolean
  quietHoursEnabled: boolean
  quietHoursStart?: string
  quietHoursEnd?: string
  timezone?: string
  notificationPreferences: Record<string, boolean>
}

// 用户个性化设置
export interface UserPersonalizationSettings {
  userId: string
  theme: string
  language: string
  timezone: string
  dateFormat: string
  timeFormat: string
  numberFormat: string
  currency: string
  dashboardLayout?: Record<string, any>
  customSettings: Record<string, any>
}

// 用户偏好设置
export interface UserPreferences {
  userId: string
  pageSize: number
  defaultViewMode: 'List' | 'Grid' | 'Table'
  showHiddenFields: boolean
  enableAnimations: boolean
  enableSounds: boolean
  autoSave: boolean
  sidebarCollapsed: boolean
  customFilters: Record<string, any>
  quickActions: string[]
}

// 用户安全设置
export interface UserSecuritySettings {
  userId: string
  passwordExpirationDays: number
  passwordComplexityEnabled: boolean
  requirePasswordChangeOnFirstLogin: boolean
  preventPasswordReuse: boolean
  maxFailedLoginAttempts: number
  accountLockoutDuration: number
  sessionTimeout: number
  requireTwoFactorForSensitiveOperations: boolean
  trustedDevices: TrustedDevice[]
}

// 受信任设备
export interface TrustedDevice {
  id: string
  userId: string
  deviceName: string
  deviceType: string
  deviceIdentifier: string
  isTrusted: boolean
  trustedTime: string
  lastUsedTime: string
  ipAddress?: string
  userAgent?: string
  expiresAt?: string
}

// 用户数据导出请求
export interface UserDataExportRequest {
  userId: string
  dataTypes: ('Profile' | 'Security' | 'Activity' | 'Sessions' | 'Notifications' | 'Settings')[]
  format: 'Json' | 'Xml' | 'Csv'
  includeSensitiveData: boolean
  dateRange?: {
    startDate: string
    endDate: string
  }
}

// 用户数据删除请求
export interface UserDataDeletionRequest {
  userId: string
  dataTypes: ('Profile' | 'Security' | 'Activity' | 'Sessions' | 'Notifications' | 'Settings')[]
  permanentDelete: boolean
  reason?: string
}

// 用户状态枚举
export enum UserStatus {
  Active = 'Active',
  Inactive = 'Inactive',
  Locked = 'Locked',
  Pending = 'Pending',
  Suspended = 'Suspended'
}

// 用户类型枚举
export enum UserType {
  System = 'System',
  Regular = 'Regular',
  Service = 'Service',
  API = 'API'
}

// 用户登录提供商枚举
export enum UserLoginProvider {
  Local = 'Local',
  Keycloak = 'Keycloak',
  AzureAD = 'AzureAD',
  Google = 'Google',
  Microsoft = 'Microsoft',
  GitHub = 'GitHub',
  LinkedIn = 'LinkedIn',
  WeChat = 'WeChat',
  DingTalk = 'DingTalk'
}

// 用户活动类型枚举
export enum UserActivityType {
  Login = 'Login',
  Logout = 'Logout',
  PasswordChange = 'PasswordChange',
  ProfileUpdate = 'ProfileUpdate',
  RoleAssignment = 'RoleAssignment',
  PermissionUpdate = 'PermissionUpdate',
  SecuritySettingChange = 'SecuritySettingChange',
  DataExport = 'DataExport',
  DataDelete = 'DataDelete',
  TwoFactorEnable = 'TwoFactorEnable',
  TwoFactorDisable = 'TwoFactorDisable',
  TrustedDeviceAdd = 'TrustedDeviceAdd',
  TrustedDeviceRemove = 'TrustedDeviceRemove'
}